package com.biz.primus.management.tms.controller;

import com.biz.primus.management.tms.feign.DeliveryOrderFeignClient;
import com.biz.primus.model.tms.enums.DeliveryPriority;
import com.biz.primus.model.tms.vo.DeliveryFeeVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.servlet.ModelAndView;


/**
 * 配送价格
 * Created by Wangjun on 2017/1/20.
 */
@Controller
@RequestMapping("deliveryPrice")
//@Secured("ROLE_PRICE")
public class DeliveryPriceController {

    private final DeliveryOrderFeignClient deliveryOrderFeignClient;

    @Autowired
    public DeliveryPriceController(DeliveryOrderFeignClient deliveryOrderFeignClient) {
        this.deliveryOrderFeignClient = deliveryOrderFeignClient;
    }

    @RequestMapping(method = RequestMethod.GET)
    @PreAuthorize("hasAuthority('OPT_PRICE_LIST')")
    public ModelAndView list() {
        ModelAndView mav = new ModelAndView("deliveryPrice/priceList");
        DeliveryFeeVo normal = deliveryOrderFeignClient.getDeliverFee(DeliveryPriority.NORMAL);
        DeliveryFeeVo immediate = deliveryOrderFeignClient.getDeliverFee(DeliveryPriority.IMMEDIATE);
        return mav.addObject("normal", normal)
                .addObject("immediate", immediate);
    }

    @ResponseBody
    @PreAuthorize("hasAuthority('OPT_PRICE_SAVE')")
    @RequestMapping(value = "update", method = RequestMethod.POST)
    public void updateImmediate(DeliveryFeeVo deliveryFeeVo) {
        deliveryOrderFeignClient.update(deliveryFeeVo);
    }

}
